package com.helloae.jmx;

import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;


public class ClientTest {

	public static void main(String[] args) throws Exception {
//		boolean res = false;
//		String ip = Constants.getHostAddree();
//		String port = Constants.CONN_PORT;
//		JMXConnector jmxc = null;
//		JMXServiceURL url = getJMXServiceURL(ip, port);
//		jmxc = JMXConnectorFactory.connect(url, null);
//		MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
//		ObjectName mbeanName = getObjectName("AdapterDeploy");
//		ObjectInstance objectInstancea = mbsc.getObjectInstance(mbeanName);
//		Object result = mbsc.invoke(objectInstancea.getObjectName(),
//				"deployAdatper", new Object[] { adapterId },
//				new String[] { "java.lang.String" });
//		res = (Boolean) result;
//		jmxc.close();
//		return res;
		JMXConnector jmxc = null;
		JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.3.106:"
				+ "3721/server");
		jmxc = JMXConnectorFactory.connect(url, null);
		MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
		ObjectName mbeanName = new ObjectName("MBeans:type=Hello");
		ObjectInstance objectInstancea = mbsc.getObjectInstance(mbeanName);
		Object result = mbsc.invoke(objectInstancea.getObjectName(), "add", new Object[]{1,2}, new String[]{"int","int"});
		System.out.println((Integer)result);
	}

}
